<?php
/**
 * User: 五哥派
 * Date: 2024/6/30
 * Tel(同WX): 17335592719
 */
namespace app\admin\controller\store;

use app\admin\controller\Base;
use app\admin\model\store\SpecsValue as SpecsValueModel;

class SpecsValue extends Base{

    protected $model;

    public function __construct(SpecsValueModel $model){
        parent::__construct();
        $this->model = $model;
    }

    /**
     * 新增逻辑
     */
    public function save() {
        $specsId = input("param.specs_id", 0, "intval");
        $name = input("param.name", "", "trim");
        // validate验证机制自行验证参数

        $data = [
            "specs_id" => $specsId,
            "name" => $name,
        ];
        $id = $this->model->save($data);

        if(!$id) {
            return error('新增失败!');
        }
        return success('新增成功!', ["id" => $id]);
    }

    public function getBySpecsId() {
        $specsId = input("param.specs_id", 0, "intval");
        if(!$specsId) {
            return error('没有数据哦!');
        }

        $result = $this->model->getBySpecsId($specsId);
        return success('OK!', $result);
    }

    public function del(){
        $id = input('id');
        $res = $this->model->delDataByID($id);
        if($res){
            return success('删除成功!');
        }else{
            return error('删除失败!');
        }
    }



}




